<?php

namespace App\Models\User;

use App\Models\BaseModel;
use App\Models\Supplier;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends BaseModel
{
    use SoftDeletes;

    public $table = 'user';
    public $timestamps = true;
    static $unguarded = true;

    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';

    //正常登录
    public const STATUS_NORMAL = 1;
    //禁止登录
    public const STATUS_DISABLE = 2;
    //已离职
    public const STATUS_LEAVE_OFFICE = 3;
    //测试
    public const STATUS_LEAVE_TEST = 4;

    protected $hidden = [
        'last_login_time',
        'category_display',
        'deleted_at',
        /*
        "reg_ip",
           "reg_ip_state",
           "reg_ip_address",
           "original",
           "reg_ip_operator"
        */
    ];

    public function roles()
    {
        return $this->hasMany(UserRole::class, 'user_id', 'id')->pluck("role_id")->toArray();
    }

    public function shop()
    {
        return $this->hasOne(Supplier::class, 'id', 'shop_id')->select(['id', 'title']);
    }

    public function roleCodes()
    {
        return $this->hasMany(UserRole::class, 'user_id', 'id')->join("role as r", "r.id", "=", "user_role.role_id")->pluck("r.name")->toArray();
    }

}